<template>
  <div>
    <div class="topnav">
      <div class="topleft">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-liebiao2" />
        </svg>
      </div>
      <div class="topcenter">
        <div class="navbtn " @click="clicktoptab(index)" :class="index==clickindex?'active':''" v-for="(item ,index) in toplist" :key="item">{{item}}</div>
        <!-- <div class="navbtn">发现</div>
        <div class="navbtn">云村</div>
        <div class="navbtn">视频</div> -->
      </div>
      <div class="topright">
        <svg class="icon" aria-hidden="true" @click="$router.push('/searchview')">
          <use xlink:href="#icon-sousuo" />
        </svg>
      </div>
    </div>
    <!-- <van-button type="primary">主要按钮</van-button> -->
  </div>
</template>

<script> 
import { mapState } from 'vuex'

    export default{
      computed:{
        ...mapState(['clickindex'])
      },
      data(){
        return{
          toplist:['我的','发现'],
          // toplist:['我的','发现','云村','视频'],
          // clickindex:this.$store.clickindex,
        }
      },
      methods: {
        clicktoptab(index){
          this.clickindex = index
          if(index==0){
            this.$store.commit('setclickindex',0)
            this.$router.push('/login')
          }
          if(index==1){
            this.$store.commit('setclickindex',1)
            this.$router.push('/')
          }
          // console.log(this.clickindex)
        }
      },
    }
</script>

<style lang="less">
.topnav {
  display: flex;
  justify-content: space-between;
  background-color: #fff;
  .topcenter {
    // display: flex;
    // justify-content: space-between;
    .navbtn {
      display: inline-block;
      margin: 0.1rem 0.2rem;
    }
    .active {
        font-weight: 900;
      }
  }
  .icon {
    width: 0.5rem;
    height: 0.5rem;
  }
}
</style>